package com.demo.simple;

import reactor.core.publisher.Mono;
import reactor.netty.Connection;
import reactor.netty.tcp.TcpClient;

// reactor-netty中TcpClient的create过程：
// https://www.jianshu.com/p/42442b47900b
public class ClientDemo {

	// 要将TCP客户端连接到给定的端点，必须创建并配置一个 TcpClient实例。默认情况下，hostis localhost和portis是12012
	public static void main(String[] args) {
		Connection connection =
                TcpClient.create()
                         .host("localhost") // 配置TCP主机
                         .port(8080)
                         // 要将数据发送到给定的端点，必须附加I / O处理程序。I / O处理程序有权访问NettyOutbound 数据
                         .handle((inbound, outbound) -> outbound.sendString(Mono.just("client: hello")))
                         // 要从给定的端点接收数据，必须附加一个I / O处理程序。I / O处理程序有权访问NettyInbound 数据
                         .handle((inbound, outbound) -> inbound.receive().then())
                         .connectNow();

        connection.onDispose()
                  .block();
	}

}
